//
//  YunDanCenterTabbar.m
//  Rabbit
//
//  Created 阿帕 on 2019/12/18.
//  Copyright © 2019 GCY. All rights reserved.
//

#import "YunDanCenterTabbar.h"

#import "YunDanCenterViewController.h"

#import "SGPagingView.h"



@interface YunDanCenterTabbar ()<SGPageTitleViewDelegate, SGPageContentCollectionViewDelegate, YunDanCenterBadgeNumDelegate,UITextFieldDelegate>
@property (nonatomic, strong) SGPageTitleView *pageTitleView;
@property (nonatomic, strong) SGPageContentCollectionView *pageContentCollectionView;
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIView *drawerView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *linesLabel;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UITextField *nameTextField;
@property (nonatomic, strong) UILabel *carNumberLabel;
@property (nonatomic, strong) UITextField *carNumberField;
@property (nonatomic, strong) UILabel *zhAddreLabel;
@property (nonatomic, strong) UITextField *zhAddreTextField;
@property (nonatomic, strong) UILabel *xhAddreLabel;
@property (nonatomic, strong) UITextField *xhAddreTextField;
@property (nonatomic, strong) UILabel *zhTimeLable;
@property (nonatomic, strong) UIButton *zhStatTimeButton;
@property (nonatomic, strong) UIButton *zhEndTimeButton;
@property (nonatomic, strong) UILabel *zhZhiLabel;
@property (nonatomic, strong) UILabel *xhTimeLabel;
@property (nonatomic, strong) UIButton *xhStatTimeButton;
@property (nonatomic, strong) UIButton *xhEndTimeButton;
@property (nonatomic, strong) UILabel *xhZhiLabel;
@property (nonatomic, strong) UIButton *resetrightButton;
@property (nonatomic, strong) UIButton *confirmButton;
@property (nonatomic, strong) UIButton *cancelButton;
@property (nonatomic, strong) NSMutableDictionary *dict;
@property (nonatomic, strong) UITapGestureRecognizer *changeVoidceSet;

@end

@implementation YunDanCenterTabbar
- (void)dealloc {
    [KNotificationCenter removeObserver:self name:YUNDANCENTERLIST_REFRESH object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupPageView];
    
    self.navigationItem.title = @"运单中心";
    UIButton *resetButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [resetButton setTitle:@"筛选" forState:UIControlStateNormal];
    resetButton.titleLabel.font = font(14);
    [resetButton setTitleColor:Dark_TextColor forState:UIControlStateNormal];
    [resetButton addTarget:self action:@selector(rightBarItemClick) forControlEvents:UIControlEventTouchUpInside];
        
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:resetButton];
    rightItem.imageInsets = UIEdgeInsetsMake(0, -15,0, 0);//设置向左偏移
    self.navigationItem.rightBarButtonItem = rightItem;
    self.view.backgroundColor = BackgroundColor;
}

- (void)setupPageView {
    
    CGFloat statusHeight = CGRectGetHeight([UIApplication sharedApplication].statusBarFrame);
    CGFloat pageTitleViewY = 0;
    if (statusHeight == 20.0) {
        pageTitleViewY = 64;
    } else {
        pageTitleViewY = 88;
    }
    
    NSArray *orderStatusArr;
    NSArray *orderTitleArr;
    NSArray *assignmentStatusArr;
    
    //    NSDictionary *userInfo = [UserDefaultUtil valueForKey:Login_Branch];
    //    NSInteger joinTeam = [[userInfo valueForKey:@"joinTeam"] integerValue];
    
    //    if ([[UserDefaultUtil valueForKey:DRIVER_TYPE] integerValue] == 0 && joinTeam == 0) {
    //        //独立司机未加入车队
    //        orderStatusArr = @[@"0", @"1", @"2", @"3", @"4", @"5", @"6"];
    //        assignmentStatusArr = @[@"all", @"waitTrans", @"", @"", @"", @"", @""];
    //        orderTitleArr = @[@"全部", @"待运输", @"运输中", @"待结算", @"待打款", @"已完成" , @"已取消"];
    //
    //    } else {
    //
    //        orderStatusArr = @[@"0", @"7", @"1", @"2", @"3", @"4", @"5", @"6"];
    //        assignmentStatusArr = @[@"all", @"waitCar", @"waitTrans", @"", @"", @"", @"", @""];
    //        orderTitleArr = @[@"全部", @"待派车", @"待运输", @"运输中", @"待结算", @"待打款", @"已完成" , @"已取消"];
    //    }
    if(Identity_CarCaptain){
        orderStatusArr = @[@"0", @"7", @"1", @"2", @"3",@"8", @"4", @"5", @"6"];
        assignmentStatusArr = @[@"all", @"waitCar", @"waitTrans", @"",@"", @"", @"", @"", @""];
        orderTitleArr = @[@"全部", @"待派车", @"待运输", @"运输中", @"待结算", @"待审核", @"待打款", @"已完成" , @"已取消"];
    }else{
        orderStatusArr = @[@"0",  @"1", @"2", @"3",@"8", @"4", @"5", @"6"];
        assignmentStatusArr = @[@"all",@"waitTrans", @"", @"", @"",@"", @"", @""];
        orderTitleArr = @[@"全部", @"待运输", @"运输中", @"待结算", @"待审核",@"待打款", @"已完成" , @"已取消"];
    }
    
    
    SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
    configure.indicatorStyle = SGIndicatorStyleDynamic;
    configure.titleFont = font(17);
    configure.titleColor = Dark_TextColor;
    configure.titleSelectedColor = Theme_ColorValue;
    configure.indicatorColor = Theme_ColorValue;
    configure.indicatorDynamicWidth = 40;
    configure.indicatorHeight = 3.0f;
    configure.showBottomSeparator = NO;
    configure.titleAdditionalWidth = 35;
    configure.badgeColor = [UIColor redColor];
    
    /// pageTitleView
    self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, 1, ScreenW, 44) delegate:self titleNames:orderTitleArr configure:configure];
    if (_selectedIndex == 6) {
        self.pageTitleView.selectedIndex = _selectedIndex;
    }
    [self.view addSubview:_pageTitleView];

    NSMutableArray *childArr = [[NSMutableArray alloc] init];
    for (int i=0; i<orderTitleArr.count; i++) {
        YunDanCenterViewController *ydcvc = [[YunDanCenterViewController alloc] init];
        ydcvc.delegate = self;
        ydcvc.orderStatus = orderStatusArr[i];
        ydcvc.assignmentStatus = assignmentStatusArr[i];
        [childArr addObject:ydcvc];
    }
    /// pageContentCollectionView
    CGFloat ContentCollectionViewHeight = self.view.frame.size.height - CGRectGetMaxY(_pageTitleView.frame);
    self.pageContentCollectionView = [[SGPageContentCollectionView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_pageTitleView.frame), ScreenW, ContentCollectionViewHeight) parentVC:self childVCs:childArr];
    _pageContentCollectionView.delegatePageContentCollectionView = self;
    [self.view addSubview:_pageContentCollectionView];

}

- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    [self.pageContentCollectionView setPageContentCollectionViewCurrentIndex:selectedIndex];
}

- (void)pageContentCollectionView:(SGPageContentCollectionView *)pageContentCollectionView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {
    [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];

}
- (void)pageContentCollectionViewDidEndDecelerating{
    [KNotificationCenter postNotificationName:YUNDANCENTERLIST_REFRESH object:self.dict];

}
#pragma mark - YunDanCenterBadgeNumDelegate
- (void)getBadgeNumberInfo:(id)badgeInfo {
    //    allTrans 全部运单数量
    //    waitTrans (integer, optional): 待运输运单数量 ,
    //    onTrans (number, optional): 运输中
    //    waitSettle (integer, optional): 待结算运单数量 ,
    //    waitPay (integer, optional): 待打款运单数量 ,
    //    finishedTrans (number, optional): 已完成运单数量 ,
    //    waitCar 待派车数量
    
    //    NSInteger    driverType = [[UserDefaultUtil valueForKey:DRIVER_TYPE] integerValue];
    //    NSDictionary *userInfo = [UserDefaultUtil valueForKey:Login_Branch];
    //    NSInteger    joinTeam = [[userInfo valueForKey:@"joinTeam"] integerValue];
    
    NSInteger startIndex = 0;
    
    //全部
    if ([badgeInfo[@"allTrans"] intValue] == 0) {
        [self.pageTitleView removeBadgeForIndex:startIndex];
    } else {
        [self.pageTitleView addNumBadgeForIndex: startIndex andNum:badgeInfo[@"allTrans"]];
    }
    //    if (driverType == 1 || driverType == 2 || (driverType == 0 && joinTeam == 1)) {
    //        //车队、车队司机、独立司机已加入车队 显示待派车菜单
    //        [self.pageTitleView addNumBadgeForIndex: startIndex+=1 andNum:badgeInfo[@"waitCar"]];
    //    }
    if(Identity_CarCaptain){
        //待派车
        if ([badgeInfo[@"waitCar"] intValue] == 0) {
            [self.pageTitleView removeBadgeForIndex:startIndex+=1];
        } else {
            [self.pageTitleView addNumBadgeForIndex: startIndex+=1 andNum:badgeInfo[@"waitCar"]];
        }
    }

    //待运输
    if ([badgeInfo[@"waitTrans"] intValue] == 0) {
        [self.pageTitleView removeBadgeForIndex:startIndex+=1];
    } else {
        [self.pageTitleView addNumBadgeForIndex: startIndex+=1 andNum:badgeInfo[@"waitTrans"]];
    }
    
    //运输中
    if ([badgeInfo[@"onTrans"] intValue] == 0) {
        [self.pageTitleView removeBadgeForIndex:startIndex+=1];
    } else {
        [self.pageTitleView addNumBadgeForIndex: startIndex+=1 andNum:badgeInfo[@"onTrans"]];
    }
    
    //待结算
    if ([badgeInfo[@"waitSettle"] intValue] == 0) {
        [self.pageTitleView removeBadgeForIndex:startIndex+=1];
    } else {
        [self.pageTitleView addNumBadgeForIndex: startIndex+=1 andNum:badgeInfo[@"waitSettle"]];
    }
    //待审核
    if ([badgeInfo[@"waitDriverCheckTrans"] intValue] == 0) {
        [self.pageTitleView removeBadgeForIndex:startIndex+=1];
    } else {
        [self.pageTitleView addNumBadgeForIndex: startIndex+=1 andNum:badgeInfo[@"waitDriverCheckTrans"]];
    }
    //待打款
    if ([badgeInfo[@"waitPay"] intValue] == 0) {
        [self.pageTitleView removeBadgeForIndex:startIndex+=1];
    } else {
        [self.pageTitleView addNumBadgeForIndex: startIndex+=1 andNum:badgeInfo[@"waitPay"]];
    }
    
    //已完成
    if ([badgeInfo[@"finishedTrans"] intValue] == 0) {
        [self.pageTitleView removeBadgeForIndex:startIndex+=1];
    } else {
        [self.pageTitleView addNumBadgeForIndex: startIndex+=1 andNum:badgeInfo[@"finishedTrans"]];
    }
    
    //已取消
    if ([badgeInfo[@"cancelTrans"] intValue] == 0) {
        [self.pageTitleView removeBadgeForIndex:startIndex+=1];
    } else {
        [self.pageTitleView addNumBadgeForIndex: startIndex+=1 andNum:badgeInfo[@"cancelTrans"]];
    }
    
    
}

-(UIView *)bgView{
    if (_bgView == nil) {
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH)];
        self.bgView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
        self.changeVoidceSet = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeVoidceSet:)];
        [self.bgView addGestureRecognizer:self.changeVoidceSet];
    }
    return _bgView;
}
- (UIView *)drawerView{
    if (_drawerView == nil) {
        self.drawerView = [[UIView alloc] initWithFrame:CGRectMake(ScreenW/4, 0, ScreenW/4*3, ScreenH)];
        self.drawerView.backgroundColor = [UIColor whiteColor];
        [self.drawerView addSubview:self.titleLabel];
        [self.drawerView addSubview:self.linesLabel];
        [self.drawerView addSubview:self.nameLabel];
        [self.drawerView addSubview:self.nameTextField];
        [self.drawerView addSubview:self.carNumberLabel];
        [self.drawerView addSubview:self.carNumberField];
        [self.drawerView addSubview:self.zhAddreLabel];
        [self.drawerView addSubview:self.zhAddreTextField];
        [self.drawerView addSubview:self.xhAddreLabel];
        [self.drawerView addSubview:self.xhAddreTextField];
        [self.drawerView addSubview:self.zhTimeLable];
        [self.drawerView addSubview:self.zhStatTimeButton];
        [self.drawerView addSubview:self.zhEndTimeButton];
        [self.drawerView addSubview:self.zhZhiLabel];
//        [self.drawerView addSubview:self.xhTimeLabel];
//        [self.drawerView addSubview:self.xhStatTimeButton];
//        [self.drawerView addSubview:self.xhEndTimeButton];
//        [self.drawerView addSubview:self.xhZhiLabel];
        [self.drawerView addSubview:self.resetrightButton];
        [self.drawerView addSubview:self.confirmButton];
        [self.drawerView addSubview:self.cancelButton];
    }
    return _drawerView;
}
-(UILabel *)titleLabel{
    if (_titleLabel == nil) {
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((ScreenW - ScreenW/4)/2 - 25, StatusBarHeight, 50, 20)];
        self.titleLabel.text = @"筛选";
    }
    return _titleLabel;
}
-(UILabel *)linesLabel{
    if (_linesLabel == nil) {
        self.linesLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame) + 10, ScreenW - ScreenW/4, 1)];
        self.linesLabel.backgroundColor = Line_TextColor;
    }
    return _linesLabel;
}
-(UILabel *)nameLabel{
    if (_nameLabel == nil) {
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.linesLabel.frame) + 20, 80, 40)];
        self.nameLabel.text = @"司机名称:";
        self.nameLabel.textColor = Light_TextColor;
        self.nameLabel.font = [UIFont systemFontOfSize:15];
    }
    return _nameLabel;
}
- (UITextField *)nameTextField{
    if (_nameTextField == nil) {
        self.nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.nameLabel.frame) + 10, CGRectGetMaxY(self.linesLabel.frame) + 20, 180, 40)];
        self.nameTextField.delegate = self;
        self.nameTextField.font = [UIFont systemFontOfSize:15];
        self.nameTextField.textColor = Light_TextColor;
        self.nameTextField.placeholder = @"请输入司机名称";
        self.nameTextField.layer.masksToBounds = YES;
        self.nameTextField.layer.borderWidth = 1;
        self.nameTextField.layer.cornerRadius = 10;
        self.nameTextField.layer.borderColor = [Light_TextColor CGColor];
    }
    return _nameTextField;
}
- (UILabel *)carNumberLabel{
    if (_carNumberLabel == nil) {
        self.carNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.nameLabel.frame) + 20, 80, 40)];
        self.carNumberLabel.text = @"车  牌  号:";
        self.carNumberLabel.textColor = Light_TextColor;
        self.carNumberLabel.font = [UIFont systemFontOfSize:15];
    }
    return _carNumberLabel;
}
- (UITextField *)carNumberField{
    if (_carNumberField == nil) {
        self.carNumberField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.carNumberLabel.frame) + 10, CGRectGetMaxY(self.nameLabel.frame) + 20, 180, 40)];
        self.carNumberField.delegate = self;
        self.carNumberField.textColor = Light_TextColor;
        self.carNumberField.font = [UIFont systemFontOfSize:15];
        self.carNumberField.placeholder = @"请输入车牌号";
        self.carNumberField.layer.masksToBounds = YES;
        self.carNumberField.layer.borderWidth = 1;
        self.carNumberField.layer.cornerRadius = 10;
        self.carNumberField.layer.borderColor = [Light_TextColor CGColor];
    }
    return _carNumberField;
}
- (UILabel *)zhAddreLabel{
    if (_zhAddreLabel == nil) {
        self.zhAddreLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.carNumberLabel.frame) + 20, 80, 40)];
        self.zhAddreLabel.text = @"装货地简称:";
        self.zhAddreLabel.textColor = Light_TextColor;
        self.zhAddreLabel.font = [UIFont systemFontOfSize:13];
    }
    return _zhAddreLabel;
}
-(UITextField *)zhAddreTextField{
    if (_zhAddreTextField == nil) {
        self.zhAddreTextField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.zhAddreLabel.frame) + 10, CGRectGetMaxY(self.carNumberLabel.frame) + 20, 180, 40)];
        self.zhAddreTextField.delegate = self;
        self.zhAddreTextField.textColor = Light_TextColor;
        self.zhAddreTextField.font = [UIFont systemFontOfSize:15];
        self.zhAddreTextField.placeholder = @"请输入装货地简称";
        self.zhAddreTextField.layer.masksToBounds = YES;
        self.zhAddreTextField.layer.borderWidth = 1;
        self.zhAddreTextField.layer.cornerRadius = 10;
        self.zhAddreTextField.layer.borderColor = [Light_TextColor CGColor];
    }
    return _zhAddreTextField;
}
- (UILabel *)xhAddreLabel{
    if (_xhAddreLabel == nil) {
        self.xhAddreLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.zhAddreLabel.frame) + 20, 80, 40)];
        self.xhAddreLabel.text = @"卸货地简称:";
        self.xhAddreLabel.textColor = Light_TextColor;
        self.xhAddreLabel.font = [UIFont systemFontOfSize:13];
    }
    return _xhAddreLabel;
}
-(UITextField *)xhAddreTextField{
    if (_xhAddreTextField == nil) {
        self.xhAddreTextField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.xhAddreLabel.frame) + 10, CGRectGetMaxY(self.zhAddreLabel.frame) + 20, 180, 40)];
        self.xhAddreTextField.delegate = self;
        self.xhAddreTextField.textColor = Light_TextColor;
        self.xhAddreTextField.font = [UIFont systemFontOfSize:15];
        self.xhAddreTextField.placeholder = @"请输入卸货地简称";
        self.xhAddreTextField.layer.masksToBounds = YES;
        self.xhAddreTextField.layer.borderWidth = 1;
        self.xhAddreTextField.layer.cornerRadius = 10;
        self.xhAddreTextField.layer.borderColor = [Light_TextColor CGColor];
    }
    return _xhAddreTextField;
}
-(UILabel *)zhTimeLable{
    if (!_zhTimeLable) {
        self.zhTimeLable = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.xhAddreLabel.frame) + 20, 80, 40)];
        self.zhTimeLable.text = @"接单时间:";
        self.zhTimeLable.textColor = Light_TextColor;
        self.zhTimeLable.font = [UIFont systemFontOfSize:15];
    }
    return _zhTimeLable;
}
-(UILabel *)xhTimeLabel{
    if (!_xhTimeLabel) {
        self.xhTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.zhStatTimeButton.frame) + 20, 80, 40)];
        self.xhTimeLabel.text = @"卸货时间:";
        self.xhTimeLabel.textColor = Light_TextColor;
        self.xhTimeLabel.font = [UIFont systemFontOfSize:15];
    }
    return _xhTimeLabel;
}
-(UIButton *)zhStatTimeButton{
    if (!_zhStatTimeButton) {
        self.zhStatTimeButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        self.zhStatTimeButton.frame = CGRectMake( 10, CGRectGetMaxY(self.zhTimeLable.frame), 100, 40);
        self.zhStatTimeButton.layer.masksToBounds = YES;
        self.zhStatTimeButton.layer.cornerRadius = 10;
        self.zhStatTimeButton.layer.borderWidth = 1;
        self.zhStatTimeButton.layer.borderColor = [Light_TextColor CGColor];
        self.zhStatTimeButton.tag = 100;
        [self.zhStatTimeButton addTarget:self action:@selector(zhButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.zhStatTimeButton setTitleColor:Light_TextColor forState:UIControlStateNormal];
        [self.zhStatTimeButton setTitle:@"开始时间" forState:UIControlStateNormal];
    }
    return _zhStatTimeButton;
}
- (UILabel *)zhZhiLabel{
    if (!_zhZhiLabel) {
        self.zhZhiLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.zhStatTimeButton.frame) + 10, CGRectGetMaxY(self.zhTimeLable.frame), 30, 40)];
        self.zhZhiLabel.text = @"至";
        self.zhZhiLabel.textAlignment = NSTextAlignmentCenter;
        self.zhZhiLabel.textColor = Light_TextColor;
        self.zhZhiLabel.font = [UIFont systemFontOfSize:15];
    }
    return _zhZhiLabel;
}
-(UIButton *)zhEndTimeButton{
    if (!_zhEndTimeButton) {
        self.zhEndTimeButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        self.zhEndTimeButton.frame = CGRectMake(CGRectGetMaxX(self.zhZhiLabel.frame) + 10, CGRectGetMaxY(self.zhTimeLable.frame), 100, 40);
        self.zhEndTimeButton.layer.masksToBounds = YES;
        self.zhEndTimeButton.layer.cornerRadius = 10;
        self.zhEndTimeButton.layer.borderWidth = 1;
        self.zhEndTimeButton.layer.borderColor = [Light_TextColor CGColor];
        self.zhEndTimeButton.tag = 101;
        [self.zhEndTimeButton addTarget:self action:@selector(zhButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.zhEndTimeButton setTitleColor:Light_TextColor forState:UIControlStateNormal];
        [self.zhEndTimeButton setTitle:@"结束时间" forState:UIControlStateNormal];
    }
    return _zhEndTimeButton;
}
-(UIButton *)xhStatTimeButton{
    if (!_xhStatTimeButton) {
        self.xhStatTimeButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        self.xhStatTimeButton.frame = CGRectMake(10, CGRectGetMaxY(self.xhTimeLabel.frame), 100, 40);
        self.xhStatTimeButton.layer.masksToBounds = YES;
        self.xhStatTimeButton.layer.cornerRadius = 10;
        self.xhStatTimeButton.layer.borderWidth = 1;
        self.xhStatTimeButton.layer.borderColor = [Light_TextColor CGColor];
        self.xhStatTimeButton.tag = 102;
        [self.xhStatTimeButton addTarget:self action:@selector(zhButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.xhStatTimeButton setTitleColor:Light_TextColor forState:UIControlStateNormal];
        [self.xhStatTimeButton setTitle:@"卸货开始时间" forState:UIControlStateNormal];
    }
    return _xhStatTimeButton;
}
- (UILabel *)xhZhiLabel{
    if (!_xhZhiLabel) {
        self.xhZhiLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.xhStatTimeButton.frame) + 10, CGRectGetMaxY(self.xhTimeLabel.frame), 30, 40)];
        self.xhZhiLabel.text = @"至";
        self.xhZhiLabel.textAlignment = NSTextAlignmentCenter;
        self.xhZhiLabel.textColor = Light_TextColor;
        self.xhZhiLabel.font = [UIFont systemFontOfSize:15];
    }
    return _xhZhiLabel;
}
-(UIButton *)xhEndTimeButton{
    if (!_xhEndTimeButton) {
        self.xhEndTimeButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        self.xhEndTimeButton.frame = CGRectMake(CGRectGetMaxX(self.xhZhiLabel.frame) + 10, CGRectGetMaxY(self.xhTimeLabel.frame), 100, 40);
        self.xhEndTimeButton.layer.masksToBounds = YES;
        self.xhEndTimeButton.layer.cornerRadius = 10;
        self.xhEndTimeButton.layer.borderWidth = 1;
        self.xhEndTimeButton.layer.borderColor = [Light_TextColor CGColor];
        self.xhEndTimeButton.tag = 103;
        [self.xhEndTimeButton addTarget:self action:@selector(zhButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.xhEndTimeButton setTitleColor:Light_TextColor forState:UIControlStateNormal];
        [self.xhEndTimeButton setTitle:@"卸货结束时间" forState:UIControlStateNormal];
    }
    return _xhEndTimeButton;
}
- (UIButton *)resetrightButton{
    if (!_resetrightButton) {
        self.resetrightButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        self.resetrightButton.frame = CGRectMake(ScreenW - 100 - ScreenW/4, StatusBarHeight, 80, 25);
        [self.resetrightButton addTarget:self action:@selector(resetrightAction) forControlEvents:(UIControlEventTouchUpInside)];
        [self.resetrightButton setTitleColor:Green_Color forState:UIControlStateNormal];
        [self.resetrightButton setTitle:@"重置" forState:UIControlStateNormal];

    }
    return _resetrightButton;
}
- (UIButton *)confirmButton{
    if (!_confirmButton) {
        self.confirmButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        self.confirmButton.frame = CGRectMake(CGRectGetMaxX(self.cancelButton.frame) + 20, ScreenH - 80, (ScreenW/4*3 - 60)/2, 50);
        [self.confirmButton addTarget:self action:@selector(confirmButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
        [self.confirmButton setTitleColor:Green_Color forState:UIControlStateNormal];
        [self.confirmButton setTitle:@"确定" forState:UIControlStateNormal];
        self.confirmButton.layer.masksToBounds = YES;
        self.confirmButton.layer.cornerRadius = 10;
        self.confirmButton.layer.borderWidth = 1;
        self.confirmButton.layer.borderColor = [Light_TextColor CGColor];
    }
    return _confirmButton;
}
- (UIButton *)cancelButton{
    if (!_cancelButton) {
        self.cancelButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        self.cancelButton.frame = CGRectMake( 20, ScreenH - 80, (ScreenW/4*3 - 60)/2, 50);
        [self.cancelButton addTarget:self action:@selector(cancelButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
        [self.cancelButton setTitleColor:Green_Color forState:UIControlStateNormal];
        [self.cancelButton setTitle:@"取消" forState:UIControlStateNormal];
        self.cancelButton.layer.masksToBounds = YES;
        self.cancelButton.layer.cornerRadius = 10;
        self.cancelButton.layer.borderWidth = 1;
        self.cancelButton.layer.borderColor = [Light_TextColor CGColor];
    }
    return _cancelButton;
}
//筛选
- (void)rightBarItemClick{
    [[UIApplication sharedApplication].keyWindow  addSubview:self.bgView];
    [self.bgView addSubview:self.drawerView];
    self.bgView.hidden = NO;
    
}
- (void)zhButtonAction:(UIButton *)btn{
    [self.nameTextField resignFirstResponder];
    [self.carNumberField resignFirstResponder];
    [self.zhAddreTextField resignFirstResponder];
    [self.xhAddreTextField resignFirstResponder];
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]initWithPickerMode:BRDatePickerModeYMDE];
    datePickerView.title = @"选择日期";
    datePickerView.isAutoSelect = NO;
    datePickerView.showToday = NO; // 是否显示“今天”
    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
        if (btn.tag == 100) {
            [self.zhStatTimeButton setTitle:selectValue forState:(UIControlStateNormal)];
        }else if (btn.tag == 101){
            [self.zhEndTimeButton setTitle:selectValue forState:(UIControlStateNormal)];
        }else if (btn.tag == 102){
            [self.xhStatTimeButton setTitle:selectValue forState:(UIControlStateNormal)];
        }else{
            [self.xhEndTimeButton setTitle:selectValue forState:(UIControlStateNormal)];
        }
    };
    [datePickerView show:nil];
}
- (void)cancelButtonAction{
    self.bgView.hidden = YES;
}
- (void)changeVoidceSet:(UITapGestureRecognizer *)sender {
    CGPoint location = [sender locationInView:self.bgView];
    DebugLog(@"--x:%f    y:%f",location.x,location.y);
    if (location.x <= ScreenW/4) {
        [self.bgView removeFromSuperview];
    }else{
        [self.nameTextField resignFirstResponder];
        [self.carNumberField resignFirstResponder];
        [self.zhAddreTextField resignFirstResponder];
        [self.xhAddreTextField resignFirstResponder];
    }

}
- (void)resetrightAction{
    [self.view endEditing:YES];
    self.nameTextField.text = @"";
    self.carNumberField.text = @"";
    self.zhAddreTextField.text = @"";
    self.xhAddreTextField.text = @"";
    [self.zhStatTimeButton setTitle:@"开始时间" forState:(UIControlStateNormal)];
    [self.zhEndTimeButton setTitle:@"结束时间" forState:(UIControlStateNormal)];
    [self.xhStatTimeButton setTitle:@"卸货开始时间" forState:(UIControlStateNormal)];
    [self.xhEndTimeButton setTitle:@"卸货结束时间" forState:(UIControlStateNormal)];
    [self.dict setValue:@"" forKey:@"shipmentName"];
    [self.dict setValue:@"" forKey:@"vehicleLicense"];
    [self.dict setValue:@"" forKey:@"placeOfShipment"];
    [self.dict setValue:@"" forKey:@"placeOfReceipt"];
    [self.dict setValue:@"" forKey:@"lastLoadingTimeStart"];
    [self.dict setValue:@"" forKey:@"lastLoadingTimeEnd"];
    [self.dict setValue:@"" forKey:@"lastUnloadingTimeStart"];
    [self.dict setValue:@"" forKey:@"lastUnloadingTimeEnd"];
    [KNotificationCenter postNotificationName:YUNDANCENTERLIST_REFRESH object:self.dict];
    self.bgView.hidden = YES;
}
- (void)confirmButtonAction{
    self.bgView.hidden = YES;
    self.dict = [NSMutableDictionary dictionary];
    [self.dict setValue:self.nameTextField.text forKey:@"shipmentName"];
    [self.dict setValue:self.carNumberField.text forKey:@"vehicleLicense"];
    [self.dict setValue:self.zhAddreTextField.text forKey:@"placeOfShipment"];
    [self.dict setValue:self.xhAddreTextField.text forKey:@"placeOfReceipt"];
    if (([self.zhStatTimeButton.titleLabel.text  isEqualToString: @"开始时间"])) {
        [self.dict setValue:@"" forKey:@"lastLoadingTimeStart"];
    }else{
        [self.dict setValue:self.zhStatTimeButton.titleLabel.text forKey:@"lastLoadingTimeStart"];
    }
    if (([self.zhEndTimeButton.titleLabel.text  isEqualToString:@"结束时间"])) {
        [self.dict setValue:@"" forKey:@"lastLoadingTimeEnd"];
    }else{
        [self.dict setValue:self.zhEndTimeButton.titleLabel.text forKey:@"lastLoadingTimeEnd"];
    }
    if (([self.xhStatTimeButton.titleLabel.text  isEqualToString: @"卸货开始时间"])) {
        [self.dict setValue:@"" forKey:@"lastUnloadingTimeStart"];
    }else{
        [self.dict setValue:self.xhStatTimeButton.titleLabel.text forKey:@"lastUnloadingTimeStart"];
    }
    if (([self.xhEndTimeButton.titleLabel.text  isEqualToString: @"卸货结束时间"])) {
        [self.dict setValue:@"" forKey:@"lastUnloadingTimeEnd"];
    }else{
        [self.dict setValue:self.xhEndTimeButton.titleLabel.text forKey:@"lastUnloadingTimeEnd"];
    }
    [KNotificationCenter postNotificationName:YUNDANCENTERLIST_REFRESH object:self.dict];
}

@end
